package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

//现在就是将此类放进SpringMVC容器里面
@RestController
//现在就是接受参数主体部分
@RequestMapping("/nursing_project")
//这个类就是分页

@RequiredArgsConstructor
public class NursingProjectController {

    //创建方法，固定返回值为ResponseResult
 /*   public ResponseResult<PageResponse<NursingProjectVo>> create(NursingProjectVo nursingProjectVo) {

    }*/
    private NursingProjectService nursingProjectService;
    //由于现在的请求为查询方法为GetMapping
    @GetMapping


    public ResponseResult getByPage(
            //现在在这里就是接收参数--因为现在就是要一页10条数据
            //以及要考虑的问题就是前端的字段要和后端的实体类要相同所以现在就是需要加注释

            @RequestParam(value = "name",required = false) String name,
            @RequestParam(value = "status",required = false)  Integer status,
            @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize
    ){

        final PageResponse<NursingProjectVo> page = nursingProjectService.getPage(name, String.valueOf(status), pageNum, pageSize);
        return ResponseResult.success(page);
    }

    //现在这个就是新增处理
    @PostMapping
    public ResponseResult addMath(@RequestBody NursingProjectDto nursingProjectDto){

        nursingProjectService.addMath(nursingProjectDto);
        return ResponseResult.success();
    }

    //现在就是根据id查询数据
    @GetMapping("/{id}")
    public ResponseResult getById(@PathVariable("id") String id){
        NursingProjectVo nursingProjectVo =  nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }


    //现在就是编辑数据
    public ResponseResult updateMath(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.updateMath(nursingProjectDto);
        return ResponseResult.success();
    }
}
